package com.laizhenghua.share.device.controller;

import com.laizhenghua.share.common.core.domain.R;
import com.laizhenghua.share.common.core.web.controller.BaseController;
import com.laizhenghua.share.device.domain.entity.Region;
import com.laizhenghua.share.device.service.IRegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author laizhenghua
 * @Date 2025/6/29 14:24
 **/
@Tag(name = "行政区划API")
@RestController
@RequestMapping("/region")
public class RegionController extends BaseController {
    private final IRegionService iRegionService;

    @Autowired
    public RegionController(IRegionService iRegionService) {
        this.iRegionService = iRegionService;
    }
    @GetMapping("/tree-select/{rootCode}")
    @Operation(summary = "获取树形结构")
    @Parameter(name = "rootCode", description = "根节点编码", required = true)
    public R<List<Region>> treeSelect(@PathVariable String rootCode) {
        List<Region> list = iRegionService.treeSelect(rootCode);
        return R.ok(list);
    }

    @GetMapping("/get/name-by-code")
    @Operation(summary = "根据行政区划代码查询行政区划名称")
    @Parameter(name = "code", description = "行政区划编码", required = true)
    public R<String> getNameByCode(@RequestParam("code") String code) {
        return iRegionService.getNameByCode(code);
    }
}
